﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using BO;

namespace ProjectQuaDep
{
    public partial class SearchNews : System.Web.UI.Page
    {
        int PageSize = 10;
        int PageIndex = lib.PageIndex;
        int ZoneID = lib.ZoneID;
        string Search = lib.KeySearch;
        int CompanyID = lib.CompanyID;
        private string sFormatNews = @"<li><a href=""{0}""><img src=""{1}"" /></a><h3><a href=""{0}"">{2}</a></h3><p>{3}</p></li>";
        protected void Page_Load(object sender, EventArgs e)
        {
             //show tin ra nao
            DataTable dt = new DataTable();
            dt = BO.News.NewsBO.GetListNewsBySearchBO(PageSize.ToString(), PageIndex.ToString(), Search);
            if (dt != null && dt.Rows.Count > 0)
            {
                for (int i = 0; i < dt.Rows.Count; i++)
                {
                    DataRow dr = dt.Rows[i];
                    string title = dr[BO.Const.tbNews.Title].ToString();
                    string sapo = dr[BO.Const.tbNews.Sapo].ToString();
                    string NewsID = dr[BO.Const.tbNews.id].ToString();
                    string url = BO.ReWriteUrl.BuildLink.BuildLinkNews(NewsID);
                    string Images = BO.Utils.CropImage(156, 130, dr[BO.Const.tbNews.Avatar].ToString());
                    ltListNews.Text += string.Format(sFormatNews, url, Images, title, sapo);
                }
                //set phan trang
                int totalRows =int.Parse(BO.News.NewsBO.CountGetListNewsBySearchBO(Search).Rows[0][Const.tbNews.TongBanGhi].ToString());
                ltCountRows.Text = ": có " + totalRows + " bài viết " + Search + " được tìm thấy";
                PaddingSearch1.PageSize = PageSize;
                int SumPage = totalRows%PageSize == 0 ? totalRows/PageSize : (totalRows/PageSize) + 1;
                PaddingSearch1.SumPage = SumPage;
                this.PaddingSearch1.LinkSite = "tim-kiem-tin-tuc.htm?KeySearch=" + Search + "&PageIndex";
                this.PaddingSearch1.Padding(PageIndex);
                PaddingSearch1.Padding(PageIndex);
                //set meta
                string Trang = "";
                if (PageIndex > 1)
                {
                    Trang = " | Trang " + PageIndex;
                }
                Page.Title = "Tìm kiếm Hồng Thủy" + Trang;
                string hDesc = "Tìm kiếm Hồng Thủy" + Trang;
                string hKey = "Tìm kiếm Hồng Thủy";
                BAL.Utils.AddMeta(this.Page, BAL.Const.MetaAttributes.Description.Id,
                                  BAL.Const.MetaAttributes.Description.Name, hDesc);
                BAL.Utils.AddMeta(this.Page, BAL.Const.MetaAttributes.Keywords.Id,
                                  BAL.Const.MetaAttributes.Keywords.Name, hKey);
                BAL.Utils.AddMeta(this.Page, BAL.Const.MetaAttributes.NewKeywords.Id,
                                  BAL.Const.MetaAttributes.NewKeywords.Name, hKey);
            }
        }
    }
}